package cst.a903dss.zyfypt_903dss.fragment;


import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import cst.a903dss.zyfypt_903dss.PagerSlidingTabStrip;
import cst.a903dss.zyfypt_903dss.R;

/**
 * A simple {@link Fragment4} subclass.
 */
public class Fragment4 extends Fragment {
    private View view=null;
    private Context context;
    private PagerSlidingTabStrip pagerSliding;
    private ViewPager viewPager;
    private Fragment41 fragment41;
    private Fragment42 fragment42;
    private DisplayMetrics dm;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        //context=getActivity();
        View view = inflater.inflate(R.layout.fragment4,container,false);
        initView(view);
        return view;
    }
 private void initView(View view){
     dm=getResources().getDisplayMetrics();
     ViewPager viewPager=(ViewPager) view.findViewById(R.id.wPager);
     pagerSliding=(PagerSlidingTabStrip) view.findViewById(R.id.pagerslidingtabstrip);
     viewPager.setAdapter(new MyPagerAdaoter(getChildFragmentManager()));
     pagerSliding.setViewPager(viewPager);
     setTabsValue();
 }
    private void setTabsValue(){
        //设置pagerSliding是自动填充满屏幕的
        pagerSliding.setShouldExpand(true);
        //设置pagerSliding的分割线是透明的
        pagerSliding.setDividerColor(Color.TRANSPARENT);
        pagerSliding.setDividerColor(Color.BLACK);
        //设置pagerSliding的高度
        pagerSliding.setUnderlineHeight((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,1,dm));
        //设置pagerSliding Indicator的高度
        pagerSliding.setIndicatorHeight((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,4,dm));
        //设置pagerSliding标题文字的大小
        pagerSliding.setTextSize((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,16,dm));
        //设置pagerSliding Indicator的颜色
        pagerSliding.setIndicatorColor(Color.parseColor("#45c01a"));
        //设置选中pagerSliding文字的颜色
        pagerSliding.setSelectedTextColor(Color.parseColor("#45c01a"));
        //取消点击pagerSliding时的背景色
        pagerSliding.setTabBackground(0);
    }
    public class MyPagerAdaoter extends FragmentStatePagerAdapter{
        private final String[] titles={"案例","项目"};

        public MyPagerAdaoter(FragmentManager childFragmentManager) {
            super(childFragmentManager);
        }


        @Override
         public CharSequence getPageTitle(int position){
             return titles[position];
         }
        @Override
        public int getCount() {
            return titles.length;
        }
        @Override
        public Fragment getItem(int position) {
            switch (position){
                case 0:
                    if(null==fragment41){
                        fragment41=new Fragment41();
                    }
                    return fragment41;
                case 1:
                    if (null==fragment42){
                        fragment42=new Fragment42();
                    }
                    return fragment42;
                default:
                    return null;
            }
        }
    }
}
